package com.ruoyi.business.controller;

import com.ruoyi.business.approvalflow.service.ITRegisterApprovalFlowService;
import com.ruoyi.business.approvalflow.vo.TRegisterApprovalFlowVo;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 退款审批流程Controller
 *
 * @author Tellsea
 * @date 2025-06-22
 */
@Api(tags = "退款审批流程Controller")
@RestController
@RequestMapping("/business/registerApprovalFlow")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class TRegisterApprovalFlowController extends BaseController {

    private final ITRegisterApprovalFlowService tRegisterApprovalFlowService;

    @ApiOperation("查询退款审批流程列表")
    @PreAuthorize("@ss.hasPermi('business:registerApprovalFlow:list')")
    @GetMapping("/list")
    public TableDataInfo<TRegisterApprovalFlowVo> list(TRegisterApprovalFlowVo entity) {
        return tRegisterApprovalFlowService.queryList(entity);
    }

    @ApiOperation("查询退款审批流程所有列表")
    @GetMapping("/listAll")
    public AjaxResult listAll(TRegisterApprovalFlowVo entity) {
        return AjaxResult.success("查询成功", tRegisterApprovalFlowService.queryAll(entity));
    }

    @ApiOperation("导出退款审批流程列表")
    @PreAuthorize("@ss.hasPermi('business:registerApprovalFlow:export')")
    @Log(title = "退款审批流程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TRegisterApprovalFlowVo entity) {
        List<TRegisterApprovalFlowVo> list = tRegisterApprovalFlowService.queryAll(entity);
        ExcelUtil<TRegisterApprovalFlowVo> util = new ExcelUtil<>(TRegisterApprovalFlowVo.class);
        util.exportExcel(response, list, "退款审批流程数据");
    }

    @ApiOperation("获取退款审批流程详细信息")
    @PreAuthorize("@ss.hasPermi('business:registerApprovalFlow:query')")
    @GetMapping(value = "/getInfo/{approvalId}")
    public AjaxResult getInfo(@PathVariable("approvalId") String approvalId) {
        return AjaxResult.success("查询成功", tRegisterApprovalFlowService.queryById(approvalId));
    }

    @ApiOperation("新增退款审批流程")
    @PreAuthorize("@ss.hasPermi('business:registerApprovalFlow:add')")
    @Log(title = "退款审批流程", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@RequestBody TRegisterApprovalFlowVo entity) {
        return toAjax(tRegisterApprovalFlowService.save(entity));
    }

    @ApiOperation("修改退款审批流程")
    @PreAuthorize("@ss.hasPermi('business:registerApprovalFlow:edit')")
    @Log(title = "退款审批流程", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody TRegisterApprovalFlowVo entity) {
        return toAjax(tRegisterApprovalFlowService.updateById(entity));
    }

    @ApiOperation("删除退款审批流程")
    @PreAuthorize("@ss.hasPermi('business:registerApprovalFlow:remove')")
    @Log(title = "退款审批流程", businessType = BusinessType.DELETE)
	@GetMapping("/remove/{approvalIds}")
    public AjaxResult remove(@PathVariable String[] approvalIds) {
        return toAjax(tRegisterApprovalFlowService.removeByIds(Arrays.asList(approvalIds)) ? 1 : 0);
    }
}
